#include <stdio.h>
#include <stdlib.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrMorphoBase.h>
#include "../macro.h"

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_erode types
/////////////////////////////////////////////////////////////////////////
#define tstErode(dtype)							\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 72, 28, 28, 28, 41, 41, 48, 54, 57, 62,		\
		   72, 72, 28, 28, 41, 41, 48, 54, 57, 55,		\
		   44, 42, 32, 32, 73, 71, 64, 62, 55, 55,		\
		   44, 42, 32, 32, 32, 73, 71, 64, 62, 55,		\
		   44, 42, 32, 32, 81, 85, 86, 82, 73, 73,		\
		   73, 73, 76, 76, 81, 85, 86, 90, 90, 92,		\
		   90, 88, 87, 87, 88, 85, 85, 35,  5,  5,		\
		   90, 88, 87, 87, 87, 85, 85, 35,  5,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_HEX, FLGR_6_CONNEX);		\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

  
int testerode_fgUINT8(void) {
  tstErode(fgUINT8);
}

int testerode_fgUINT16(void) {
  tstErode(fgUINT16);
}

int testerode_fgUINT32(void) {
  tstErode(fgUINT32);
}

int testerode_fgINT8(void) {
  tstErode(fgINT8);
}

int testerode_fgINT16(void) {
  tstErode(fgINT16);
}

int testerode_fgINT32(void) {
  tstErode(fgINT32);
}

int testerode_fgFLOAT32(void) {
  tstErode(fgFLOAT32);
}

int testerode_fgFLOAT64(void) {
  tstErode(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_erode2 types
/////////////////////////////////////////////////////////////////////////
#define tstErode2(dtype)						\
  									\
  dtype rawsrc[]={105, 115,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  76,  75,  76,  76,  78,  75,  77,  78,  76,	\
		  75,  79,  77,  76,  77,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32, 100, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96, 100,  96,  98,  98,  97, 102,  99,	\
		  98,  96,  99, 102,  98,  93, 100,  99,  94,  96,	\
		  94,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
  									\
  dtype rawref[]={105, 105,  28,  28,  41,  41,  48,  54,  57,  62,	\
		  72,  72,  75,  28,  41,  41,  48,  54,  57,  62,	\
		  72,  75,  75,  76,  76,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32,  32,  77,  73,  71,  64,  62,	\
		  50,  44,  42,  32,  81,  85,  86,  88,  82,  73,	\
		  91,  73,  76,  76,  81,  85,  86,  90,  90,  93,	\
		  91,  96,  96,  99,  96,  93,  93,  97,  94,  94,	\
		  94,  90,  88,  87,  87,  88,  85,  85,  35,   5};	\
									\
  dtype rawnhb[9]={0,  1,0,						\
		   1,1,0,						\
		   0,  0,0};						\
									\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_USER_SHAPE, FLGR_6_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  flgr2d_import_raw_ptr(nhb,rawnhb);					\
									\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

  
int testerode2_fgUINT8(void) {
  tstErode2(fgUINT8);
}

int testerode2_fgUINT16(void) {
  tstErode2(fgUINT16);
}

int testerode2_fgUINT32(void) {
  tstErode2(fgUINT32);
}

int testerode2_fgINT8(void) {
  tstErode2(fgINT8);
}

int testerode2_fgINT16(void) {
  tstErode2(fgINT16);
}

int testerode2_fgINT32(void) {
  tstErode2(fgINT32);
}

int testerode2_fgFLOAT32(void) {
  tstErode2(fgFLOAT32);
}

int testerode2_fgFLOAT64(void) {
  tstErode2(fgFLOAT64);
}





/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_erode2 types
/////////////////////////////////////////////////////////////////////////
#define tstErode3(dtype)						\
  									\
  dtype rawsrc[]={105, 115,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  76,  75,  76,  76,  78,  75,  77,  78,  76,	\
		  75,  79,  77,  76,  77,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32, 100, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96, 100,  96,  98,  98,  97, 102,  99,	\
		  98,  96,  99, 102,  98,  93, 100,  99,  94,  96,	\
		  94,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
  									\
  dtype rawref[]={72,  28,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  75,  75,  76,  73,  71,  64,  62,  55,  55,	\
		  44,  42,  32,  32,  73,  71,  64,  62,  55,  55,	\
		  44,  42,  32,  32,  85,  86,  88,  82,  73,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  92,  92,	\
		  91,  96,  96,  96,  93,  93,  97,  94,  94,  96,	\
		  90,  88,  87,  87,  88,  85,  85,  35,   5,   5,	\
		  90,  88,  87,  87,  88,  85,  85,  35,   5,   5};	\
									\
  dtype rawnhb[9]={0,0,0,						\
		   0,1,1,						\
		   0,1,1};						\
									\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3, 3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_USER_SHAPE, FLGR_8_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  flgr2d_import_raw_ptr(nhb,rawnhb);					\
									\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testerode3_fgUINT8(void) {
  tstErode3(fgUINT8);
}

int testerode3_fgUINT16(void) {
  tstErode3(fgUINT16);
}

int testerode3_fgUINT32(void) {
  tstErode3(fgUINT32);
}

int testerode3_fgINT8(void) {
  tstErode3(fgINT8);
}

int testerode3_fgINT16(void) {
  tstErode3(fgINT16);
}

int testerode3_fgINT32(void) {
  tstErode3(fgINT32);
}

int testerode3_fgFLOAT32(void) {
  tstErode3(fgFLOAT32);
}

int testerode3_fgFLOAT64(void) {
  tstErode3(fgFLOAT64);
}





/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_minkowski_sub types
/////////////////////////////////////////////////////////////////////////
#define tstMinkowski_Sub(dtype)						\
  									\
  dtype rawsrc[]={105, 115,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  76,  75,  76,  76,  78,  75,  77,  78,  76,	\
		  75,  79,  77,  76,  77,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32, 100, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96, 100,  96,  98,  98,  97, 102,  99,	\
		  98,  96,  99, 102,  98,  93, 100,  99,  94,  96,	\
		  94,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
  									\
  dtype rawref[]={105, 105,  28,  28,  41,  41,  48,  54,  57,  62,	\
		  72,  72,  75,  28,  41,  41,  48,  54,  57,  62,	\
		  72,  75,  75,  76,  76,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32,  32,  77,  73,  71,  64,  62,	\
		  50,  44,  42,  32,  81,  85,  86,  88,  82,  73,	\
		  91,  73,  76,  76,  81,  85,  86,  90,  90,  93,	\
		  91,  96,  96,  99,  96,  93,  93,  97,  94,  94,	\
		  94,  90,  88,  87,  87,  88,  85,  85,  35,   5};	\
									\
  dtype rawnhb[9]={0, 0,0,						\
		   0,1,1,						\
		   0, 0,1};						\
									\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_USER_SHAPE, FLGR_6_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  flgr2d_import_raw_ptr(nhb,rawnhb);					\
									\
  ret=flgr2d_minkowski_sub(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

  
int testminkowski_sub_fgUINT8(void) {
  tstMinkowski_Sub(fgUINT8);
}

int testminkowski_sub_fgUINT16(void) {
  tstMinkowski_Sub(fgUINT16);
}

int testminkowski_sub_fgUINT32(void) {
  tstMinkowski_Sub(fgUINT32);
}

int testminkowski_sub_fgINT8(void) {
  tstMinkowski_Sub(fgINT8);
}

int testminkowski_sub_fgINT16(void) {
  tstMinkowski_Sub(fgINT16);
}

int testminkowski_sub_fgINT32(void) {
  tstMinkowski_Sub(fgINT32);
}

int testminkowski_sub_fgFLOAT32(void) {
  tstMinkowski_Sub(fgFLOAT32);
}

int testminkowski_sub_fgFLOAT64(void) {
  tstMinkowski_Sub(fgFLOAT64);
}





/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_minkowski_add types
/////////////////////////////////////////////////////////////////////////
#define tstMinkowski_Add(dtype)						\
  									\
  dtype rawsrc[]={105, 115,  28,  41,  41,  48,  54,  57,  62,  70,	\
		  72,  76,  75,  76,  76,  78,  75,  77,  78,  76,	\
		  75,  79,  77,  76,  77,  73,  71,  64,  62,  55,	\
		  50,  44,  42,  32, 100, 112, 100,  88,  82,  73,	\
		  73,  76,  76,  81,  85,  86,  90,  90,  93,  92,	\
		  91,  96,  96, 100,  96,  98,  98,  97, 102,  99,	\
		  98,  96,  99, 102,  98,  93, 100,  99,  94,  96,	\
		  94,  90,  88,  87,  88,  88,  85,  87,  35,   5};	\
  									\
  dtype rawref[]={105, 115, 115,  41,  41,  48,  54,  57,  62,  70,	\
		  72, 105, 115,  76,  76,  78,  78,  77,  78,  78,	\
		  75,  79,  79,  77,  77,  78,  75,  77,  78,  76,	\
		  50,  75,  79,  77, 100, 112, 112, 100,  88,  82,	\
		  73,  76,  76,  81, 100, 112, 100,  90,  93,  93,	\
		  91,  96,  96, 100, 100,  98,  98,  98, 102, 102,	\
		  98,  98,  99, 102, 102,  98, 100, 100, 102,  99,	\
		  94,  98,  96,  99, 102,  98,  93, 100,  99,  94};	\
									\
  dtype rawnhb[9]={0,  0,0,						\
		   0,1,1,						\
		   0,  0,1};						\
									\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_USER_SHAPE, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  flgr2d_import_raw_ptr(nhb,rawnhb);					\
									\
  ret=flgr2d_minkowski_add(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

  
int testminkowski_add_fgUINT8(void) {
  tstMinkowski_Add(fgUINT8);
}

int testminkowski_add_fgUINT16(void) {
  tstMinkowski_Add(fgUINT16);
}

int testminkowski_add_fgUINT32(void) {
  tstMinkowski_Add(fgUINT32);
}

int testminkowski_add_fgINT8(void) {
  tstMinkowski_Add(fgINT8);
}

int testminkowski_add_fgINT16(void) {
  tstMinkowski_Add(fgINT16);
}

int testminkowski_add_fgINT32(void) {
  tstMinkowski_Add(fgINT32);
}

int testminkowski_add_fgFLOAT32(void) {
  tstMinkowski_Add(fgFLOAT32);
}

int testminkowski_add_fgFLOAT64(void) {
  tstMinkowski_Add(fgFLOAT64);
}






/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_dilate types
/////////////////////////////////////////////////////////////////////////
#define tstDilate(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={115,115,115, 76, 78, 78, 77, 78, 78, 76,		\
		  105,115,115, 77, 78, 78, 78, 78, 78, 78,		\
		  79, 79, 79,123,123,112,100, 88, 82, 76,		\
		  75, 79, 79,123,123,123,112,100, 93, 93,		\
		  96, 96,100,123,123,112,100,102,102, 99,		\
		  98, 98,100,102,102, 98,100,102,102,102,		\
		  98, 99,102,102,102,100,100,102,102, 99,		\
		  98, 98, 99,102,102, 98,100,100, 99, 96};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1


int testdilate_fgUINT8(void) {
  tstDilate(fgUINT8);
}
int testdilate_fgUINT16(void) {
  tstDilate(fgUINT16);
}
int testdilate_fgUINT32(void) {
  tstDilate(fgUINT32);
}
int testdilate_fgINT8(void) {
  tstDilate(fgINT8);
}
int testdilate_fgINT16(void) {
  tstDilate(fgINT16);
}
int testdilate_fgINT32(void) {
  tstDilate(fgINT32);
}
int testdilate_fgFLOAT32(void) {
  tstDilate(fgFLOAT32);
}
int testdilate_fgFLOAT64(void) {
  tstDilate(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_median types
/////////////////////////////////////////////////////////////////////////
#define tstMedian(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105, 76, 75, 41, 48, 54, 57, 62, 70, 70,		\
		  76, 76, 76, 76, 76, 75, 73, 71, 64, 70,		\
		  75, 75, 76, 76, 77, 77, 75, 77, 73, 73,		\
		  73, 73, 76, 76, 81, 86, 88, 88, 82, 82,		\
		  76, 76, 76, 85, 96, 98, 90, 90, 92, 93,		\
		  96, 96, 96, 96, 98, 96, 97, 98, 97, 96,		\
		  96, 96, 96, 98, 96, 98, 97, 97, 96, 96,		\
		  94, 94, 90, 88, 88, 88, 88, 87, 87, 94};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_median(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testmedian_fgUINT8(void) {
  tstMedian(fgUINT8);
}
int testmedian_fgUINT16(void) {
  tstMedian(fgUINT16);
}
int testmedian_fgUINT32(void) {
  tstMedian(fgUINT32);
}
int testmedian_fgINT8(void) {
  tstMedian(fgINT8);
}
int testmedian_fgINT16(void) {
  tstMedian(fgINT16);
}
int testmedian_fgINT32(void) {
  tstMedian(fgINT32);
}
int testmedian_fgFLOAT32(void) {
  tstMedian(fgFLOAT32);
}
int testmedian_fgFLOAT64(void) {
  tstMedian(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_gradient_inner types
/////////////////////////////////////////////////////////////////////////
#define tstGradient_Inner(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 33, 87,  0, 13,  0,  7,  6,  3,  5,  8,		\
		   0,  4, 47, 48, 35, 37, 27, 23, 21, 21,		\
		   31, 37, 45, 44,  4,  2,  7,  2,  7,  0,		\
		   6,  2, 10,  0, 91, 39, 29, 24, 20, 18,		\
		   29, 34, 44, 49,  4,  1,  4,  8, 20, 19,		\
		   18, 23, 20, 24, 15, 13, 12,  7, 12,  7,		\
		   8,  8, 12, 15, 10,  8, 15, 64, 89, 91,		\
		   4,  2,  1,  0,  1,  3,  0, 52, 30,  0};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_gradient_inner(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testgradient_inner_fgUINT8(void) {
  tstGradient_Inner(fgUINT8);
}
int testgradient_inner_fgUINT16(void) {
  tstGradient_Inner(fgUINT16);
}
int testgradient_inner_fgUINT32(void) {
  tstGradient_Inner(fgUINT32);
}
int testgradient_inner_fgINT8(void) {
  tstGradient_Inner(fgINT8);
}
int testgradient_inner_fgINT16(void) {
  tstGradient_Inner(fgINT16);
}
int testgradient_inner_fgINT32(void) {
  tstGradient_Inner(fgINT32);
}
int testgradient_inner_fgFLOAT32(void) {
  tstGradient_Inner(fgFLOAT32);
}
int testgradient_inner_fgFLOAT64(void) {
  tstGradient_Inner(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_gradient_outer types
/////////////////////////////////////////////////////////////////////////
#define tstGradient_Outer(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 10,  0, 87, 35, 37, 30, 23, 21, 16,  6,		\
		   33, 39, 40,  1,  2,  0,  3,  1,  0,  2,		\
		   4,  0,  2, 47, 46, 39, 29, 24, 20, 21,		\
		   25, 35, 37, 91,  0, 11, 12, 12, 11, 20,		\
		   23, 20, 24, 42, 38, 26, 10, 12,  9,  7,		\
		   7,  2,  4,  2,  6,  0,  2,  5,  0,  3,		\
		   0,  3,  3,  0,  4,  7,  0,  3,  8,  3,		\
		   4,  8, 11, 15, 14, 10, 15, 13, 64, 91};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_gradient_outer(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testgradient_outer_fgUINT8(void) {
  tstGradient_Outer(fgUINT8);
}
int testgradient_outer_fgUINT16(void) {
  tstGradient_Outer(fgUINT16);
}
int testgradient_outer_fgUINT32(void) {
  tstGradient_Outer(fgUINT32);
}
int testgradient_outer_fgINT8(void) {
  tstGradient_Outer(fgINT8);
}
int testgradient_outer_fgINT16(void) {
  tstGradient_Outer(fgINT16);
}
int testgradient_outer_fgINT32(void) {
  tstGradient_Outer(fgINT32);
}
int testgradient_outer_fgFLOAT32(void) {
  tstGradient_Outer(fgFLOAT32);
}
int testgradient_outer_fgFLOAT64(void) {
  tstGradient_Outer(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_gradient_thick types
/////////////////////////////////////////////////////////////////////////
#define tstGradient_Thick(dtype)					\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 43, 87, 87, 48, 37, 37, 29, 24, 21, 14,		\
		   33, 43, 87, 49, 37, 37, 30, 24, 21, 23,		\
		   35, 37, 47, 91, 50, 41, 36, 26, 27, 21,		\
		   31, 37, 47, 91, 91, 50, 41, 36, 31, 38,		\
		   52, 54, 68, 91, 42, 27, 14, 20, 29, 26,		\
		   25, 25, 24, 26, 21, 13, 14, 12, 12, 10,		\
		   8, 11, 15, 15, 14, 15, 15, 67, 97, 94,		\
		   8, 10, 12, 15, 15, 13, 15, 65, 94, 91};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_gradient_thick(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testgradient_thick_fgUINT8(void) {
  tstGradient_Thick(fgUINT8);
}
int testgradient_thick_fgUINT16(void) {
  tstGradient_Thick(fgUINT16);
}
int testgradient_thick_fgUINT32(void) {
  tstGradient_Thick(fgUINT32);
}
int testgradient_thick_fgINT8(void) {
  tstGradient_Thick(fgINT8);
}
int testgradient_thick_fgINT16(void) {
  tstGradient_Thick(fgINT16);
}
int testgradient_thick_fgINT32(void) {
  tstGradient_Thick(fgINT32);
}
int testgradient_thick_fgFLOAT32(void) {
  tstGradient_Thick(fgFLOAT32);
}
int testgradient_thick_fgFLOAT64(void) {
  tstGradient_Thick(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_open types
/////////////////////////////////////////////////////////////////////////
#define tstOpen(dtype)							\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 72, 72, 28, 41, 41, 48, 54, 57, 62, 62,		\
		   72, 72, 72, 41, 73, 73, 71, 64, 62, 62,		\
		   72, 72, 42, 73, 73, 73, 71, 64, 62, 55,		\
		   44, 44, 42, 32, 81, 85, 86, 86, 82, 73,		\
		   73, 76, 76, 81, 85, 86, 90, 90, 92, 92,		\
		   90, 90, 88, 87, 88, 88, 90, 90, 92, 92,		\
		   90, 90, 88, 88, 88, 88, 90, 90, 92, 92,		\
		   90, 90, 88, 87, 88, 88, 85, 85, 35,  5};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_open(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testopen_fgUINT8(void) {
  tstOpen(fgUINT8);
}
int testopen_fgUINT16(void) {
  tstOpen(fgUINT16);
}
int testopen_fgUINT32(void) {
  tstOpen(fgUINT32);
}
int testopen_fgINT8(void) {
  tstOpen(fgINT8);
}
int testopen_fgINT16(void) {
  tstOpen(fgINT16);
}
int testopen_fgINT32(void) {
  tstOpen(fgINT32);
}
int testopen_fgFLOAT32(void) {
  tstOpen(fgFLOAT32);
}
int testopen_fgFLOAT64(void) {
  tstOpen(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close types
/////////////////////////////////////////////////////////////////////////
#define tstClose(dtype)							\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={105,115, 76, 76, 76, 77, 77, 77, 76, 76,		\
		  79, 79, 77, 76, 76, 78, 77, 77, 78, 76,		\
		  75, 79, 77, 77, 78, 78, 78, 78, 76, 76,		\
		  75, 75, 79, 79,123,112,100, 88, 82, 76,		\
		  75, 79, 79,100, 98, 98,100, 93, 93, 93,		\
		  96, 96, 96,100, 98, 98, 98,100,102, 99,		\
		  98, 98, 99,102, 98, 98,100, 99, 96, 96,		\
		  98, 98, 98, 99, 98, 98, 98, 99, 96, 96};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_close(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testclose_fgUINT8(void) {
  tstClose(fgUINT8);
}
int testclose_fgUINT16(void) {
  tstClose(fgUINT16);
}
int testclose_fgUINT32(void) {
  tstClose(fgUINT32);
}
int testclose_fgINT8(void) {
  tstClose(fgINT8);
}
int testclose_fgINT16(void) {
  tstClose(fgINT16);
}
int testclose_fgINT32(void) {
  tstClose(fgINT32);
}
int testclose_fgFLOAT32(void) {
  tstClose(fgFLOAT32);
}
int testclose_fgFLOAT64(void) {
  tstClose(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_open_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstOpen_Tophat(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={ 33, 43,  0,  0,  0,  0,  0,  0,  0,  8,		\
		   0,  4,  3, 35,  3,  5,  4, 13, 16, 14,		\
		   3,  7, 35,  3,  4,  0,  0,  0,  0,  0,		\
		   6,  0,  0,  0, 42, 27, 14,  2,  0,  0,		\
		   0,  0,  0,  0,  0,  0,  0,  0,  1,  0,		\
		   1,  6,  8, 13,  8, 10,  8,  7, 10,  7,		\
		   8,  6, 11, 14, 10,  5, 10,  9,  2,  4,		\
		   4,  0,  0,  0,  0,  0,  0,  2,  0,  0};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_open_tophat(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testopen_tophat_fgUINT8(void) {
  tstOpen_Tophat(fgUINT8);
}
int testopen_tophat_fgUINT16(void) {
  tstOpen_Tophat(fgUINT16);
}
int testopen_tophat_fgUINT32(void) {
  tstOpen_Tophat(fgUINT32);
}
int testopen_tophat_fgINT8(void) {
  tstOpen_Tophat(fgINT8);
}
int testopen_tophat_fgINT16(void) {
  tstOpen_Tophat(fgINT16);
}
int testopen_tophat_fgINT32(void) {
  tstOpen_Tophat(fgINT32);
}
int testopen_tophat_fgFLOAT32(void) {
  tstOpen_Tophat(fgFLOAT32);
}
int testopen_tophat_fgFLOAT64(void) {
  tstOpen_Tophat(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstClose_Tophat(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={  0,  0, 48, 35, 35, 29, 23, 20, 14,  6,		\
		    7,  3,  2,  0,  0,  0,  2,  0,  0,  0,		\
		    0,  0,  0,  1,  1,  5,  7, 14, 14, 21,		\
		    25, 31, 37, 47,  0,  0,  0,  0,  0,  3,		\
		    2,  3,  3, 19, 13, 12, 10,  3,  0,  1,		\
		    5,  0,  0,  0,  2,  0,  0,  3,  0,  0,		\
		    0,  2,  0,  0,  0,  5,  0,  0,  2,  0,		\
		    4,  8, 10, 12, 10, 10, 13, 12, 61, 91};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3,1, flgr_get_type_from_string(#dtype),FLGR_HEX, FLGR_6_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_close_tophat(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testclose_tophat_fgUINT8(void) {
  tstClose_Tophat(fgUINT8);
}
int testclose_tophat_fgUINT16(void) {
  tstClose_Tophat(fgUINT16);
}
int testclose_tophat_fgUINT32(void) {
  tstClose_Tophat(fgUINT32);
}
int testclose_tophat_fgINT8(void) {
  tstClose_Tophat(fgINT8);
}
int testclose_tophat_fgINT16(void) {
  tstClose_Tophat(fgINT16);
}
int testclose_tophat_fgINT32(void) {
  tstClose_Tophat(fgINT32);
}
int testclose_tophat_fgFLOAT32(void) {
  tstClose_Tophat(fgFLOAT32);
}
int testclose_tophat_fgFLOAT64(void) {
  tstClose_Tophat(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstErodeSq(dtype)						\
									\
  dtype rawsrc[]={0, 5, 0, 0, 0, 3, 8, 5, 0, 0,				\
		  0, 0, 7, 9, 7, 0, 8, 0, 0, 9,				\
		  0, 0, 5, 0, 0, 5, 8, 0, 5, 9,				\
		  0, 3, 0, 0, 0, 0, 0, 0, 0, 9,				\
		  3, 5, 3, 0, 5, 4, 5, 4, 0, 0,				\
		  2, 3, 3, 0, 4, 4, 4, 0, 3, 0,				\
		  2, 3, 0, 3, 4, 4, 4, 4, 0, 0,				\
		  0, 0, 5, 0, 5, 4, 0, 0, 0, 5};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  2, 0, 0, 0, 0, 4, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3, img->spp, img->type,	\
				      FLGR_RECT, FLGR_8_CONNEX);	\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testerodeSq_fgBIT(void) {
  tstErodeSq(fgBIT);
}
int testerodeSq_fgUINT8(void) {
  tstErodeSq(fgUINT8);
}
int testerodeSq_fgUINT16(void) {
  tstErodeSq(fgUINT16);
}
int testerodeSq_fgUINT32(void) {
  tstErodeSq(fgUINT32);
}
int testerodeSq_fgINT8(void) {
  tstErodeSq(fgINT8);
}
int testerodeSq_fgINT16(void) {
  tstErodeSq(fgINT16);
}
int testerodeSq_fgINT32(void) {
  tstErodeSq(fgINT32);
}
int testerodeSq_fgFLOAT32(void) {
  tstErodeSq(fgFLOAT32);
}
int testerodeSq_fgFLOAT64(void) {
  tstErodeSq(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstErodeCr(dtype)						\
									\
  dtype rawsrc[]={0, 1, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 1, 1, 0, 1, 0, 0, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 0, 1, 1,				\
		  1, 1, 0, 1, 1, 1, 1, 0, 0, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 1, 1, 1, 1, 0, 1, 0,				\
		  1, 1, 0, 1, 1, 1, 1, 1, 0, 0,				\
		  0, 0, 1, 0, 1, 1, 0, 0, 0, 1};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 1, 1, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 1, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_DIAMOND, FLGR_8_CONNEX);	\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testerodeCr_fgBIT(void) {
  tstErodeCr(fgBIT);
}
int testerodeCr_fgUINT8(void) {
  tstErodeCr(fgUINT8);
}
int testerodeCr_fgUINT16(void) {
  tstErodeCr(fgUINT16);
}
int testerodeCr_fgUINT32(void) {
  tstErodeCr(fgUINT32);
}
int testerodeCr_fgINT8(void) {
  tstErodeCr(fgINT8);
}
int testerodeCr_fgINT16(void) {
  tstErodeCr(fgINT16);
}
int testerodeCr_fgINT32(void) {
  tstErodeCr(fgINT32);
}
int testerodeCr_fgFLOAT32(void) {
  tstErodeCr(fgFLOAT32);
}
int testerodeCr_fgFLOAT64(void) {
  tstErodeCr(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstErodeHex(dtype)						\
									\
  dtype rawsrc[]={0, 1, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 1, 1, 0, 1, 0, 0, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 0, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 0, 0, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 1, 1, 1, 1, 0, 1, 0,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 0,				\
		  0, 0, 1, 0, 1, 1, 0, 0, 0, 1};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 1, 1, 1, 0, 0, 0, 0, 0, 0,				\
		  1, 1, 1, 1, 1, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_HEX, FLGR_6_CONNEX);		\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testerodeHex_fgBIT(void) {
  tstErodeHex(fgBIT);
}
int testerodeHex_fgUINT8(void) {
  tstErodeHex(fgUINT8);
}
int testerodeHex_fgUINT16(void) {
  tstErodeHex(fgUINT16);
}
int testerodeHex_fgUINT32(void) {
  tstErodeHex(fgUINT32);
}
int testerodeHex_fgINT8(void) {
  tstErodeHex(fgINT8);
}
int testerodeHex_fgINT16(void) {
  tstErodeHex(fgINT16);
}
int testerodeHex_fgINT32(void) {
  tstErodeHex(fgINT32);
}
int testerodeHex_fgFLOAT32(void) {
  tstErodeHex(fgFLOAT32);
}
int testerodeHex_fgFLOAT64(void) {
  tstErodeHex(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstErodeOct(dtype)						\
									\
  dtype rawsrc[]={0, 1, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 1, 1, 0, 1, 0, 0, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 0, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 0,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 0,				\
		  0, 0, 1, 0, 1, 1, 0, 0, 0, 1};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 1, 1, 1, 0, 0, 0, 0, 0, 0,				\
		  1, 1, 1, 1, 1, 1, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_OCTAGON, FLGR_8_CONNEX);	\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_erode(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testerodeOct_fgBIT(void) {
  tstErodeOct(fgBIT);
}
int testerodeOct_fgUINT8(void) {
  tstErodeOct(fgUINT8);
}
int testerodeOct_fgUINT16(void) {
  tstErodeOct(fgUINT16);
}
int testerodeOct_fgUINT32(void) {
  tstErodeOct(fgUINT32);
}
int testerodeOct_fgINT8(void) {
  tstErodeOct(fgINT8);
}
int testerodeOct_fgINT16(void) {
  tstErodeOct(fgINT16);
}
int testerodeOct_fgINT32(void) {
  tstErodeOct(fgINT32);
}
int testerodeOct_fgFLOAT32(void) {
  tstErodeOct(fgFLOAT32);
}
int testerodeOct_fgFLOAT64(void) {
  tstErodeOct(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstDilateSq(dtype)						\
									\
  dtype rawsrc[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 1, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 0, 0, 0, 1,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 1, 0, 0, 0};			\
									\
  dtype rawref[]={0, 0, 0, 0, 1, 1, 1, 1, 1, 0,				\
		  0, 0, 0, 0, 1, 1, 1, 1, 1, 0,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  0, 0, 0, 0, 1, 1, 1, 1, 1, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_RECT, FLGR_8_CONNEX);	\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilateSq_fgBIT(void) {
  tstDilateSq(fgBIT);
}
int testdilateSq_fgUINT8(void) {
  tstDilateSq(fgUINT8);
}
int testdilateSq_fgUINT16(void) {
  tstDilateSq(fgUINT16);
}
int testdilateSq_fgUINT32(void) {
  tstDilateSq(fgUINT32);
}
int testdilateSq_fgINT8(void) {
  tstDilateSq(fgINT8);
}
int testdilateSq_fgINT16(void) {
  tstDilateSq(fgINT16);
}
int testdilateSq_fgINT32(void) {
  tstDilateSq(fgINT32);
}
int testdilateSq_fgFLOAT32(void) {
  tstDilateSq(fgFLOAT32);
}
int testdilateSq_fgFLOAT64(void) {
  tstDilateSq(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstDilateCr(dtype)						\
									\
  dtype rawsrc[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 1, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 0, 0, 0, 1,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 1, 0, 0, 0};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 1, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  1, 0, 0, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 0, 0, 0, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 0, 0, 1, 1, 1, 1,				\
		  1, 1, 0, 0, 0, 0, 1, 0, 1, 1,				\
		  1, 1, 0, 0, 0, 1, 1, 1, 0, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_DIAMOND, FLGR_8_CONNEX);	\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilateCr_fgBIT(void) {
  tstDilateCr(fgBIT);
}
int testdilateCr_fgUINT8(void) {
  tstDilateCr(fgUINT8);
}
int testdilateCr_fgUINT16(void) {
  tstDilateCr(fgUINT16);
}
int testdilateCr_fgUINT32(void) {
  tstDilateCr(fgUINT32);
}
int testdilateCr_fgINT8(void) {
  tstDilateCr(fgINT8);
}
int testdilateCr_fgINT16(void) {
  tstDilateCr(fgINT16);
}
int testdilateCr_fgINT32(void) {
  tstDilateCr(fgINT32);
}
int testdilateCr_fgFLOAT32(void) {
  tstDilateCr(fgFLOAT32);
}
int testdilateCr_fgFLOAT64(void) {
  tstDilateCr(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstDilateHex(dtype)						\
									\
  dtype rawsrc[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 1, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 0, 0, 0, 1,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 1, 0, 0, 0};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  0, 0, 0, 0, 0, 1, 1, 1, 1, 0,				\
		  1, 1, 0, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 0, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 0, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 0, 1, 1, 1, 1, 1,				\
		  1, 1, 0, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_HEX, FLGR_6_CONNEX);		\
  									\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilateHex_fgBIT(void) {
  tstDilateHex(fgBIT);
}
int testdilateHex_fgUINT8(void) {
  tstDilateHex(fgUINT8);
}
int testdilateHex_fgUINT16(void) {
  tstDilateHex(fgUINT16);
}
int testdilateHex_fgUINT32(void) {
  tstDilateHex(fgUINT32);
}
int testdilateHex_fgINT8(void) {
  tstDilateHex(fgINT8);
}
int testdilateHex_fgINT16(void) {
  tstDilateHex(fgINT16);
}
int testdilateHex_fgINT32(void) {
  tstDilateHex(fgINT32);
}
int testdilateHex_fgFLOAT32(void) {
  tstDilateHex(fgFLOAT32);
}
int testdilateHex_fgFLOAT64(void) {
  tstDilateHex(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstDilateOct(dtype)						\
									\
  dtype rawsrc[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 1, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 0, 0, 0, 1,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  1, 0, 0, 0, 0, 0, 1, 0, 0, 0};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  0, 0, 0, 0, 1, 1, 1, 1, 1, 0,				\
		  1, 1, 0, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 0, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 0, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 1, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, img->spp, img->type,	\
				      FLGR_OCTAGON, FLGR_8_CONNEX);	\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_dilate(img,imgsrc,nhb);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilateOct_fgBIT(void) {
  tstDilateOct(fgBIT);
}
int testdilateOct_fgUINT8(void) {
  tstDilateOct(fgUINT8);
}
int testdilateOct_fgUINT16(void) {
  tstDilateOct(fgUINT16);
}
int testdilateOct_fgUINT32(void) {
  tstDilateOct(fgUINT32);
}
int testdilateOct_fgINT8(void) {
  tstDilateOct(fgINT8);
}
int testdilateOct_fgINT16(void) {
  tstDilateOct(fgINT16);
}
int testdilateOct_fgINT32(void) {
  tstDilateOct(fgINT32);
}
int testdilateOct_fgFLOAT32(void) {
  tstDilateOct(fgFLOAT32);
}
int testdilateOct_fgFLOAT64(void) {
  tstDilateOct(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_close_tophat types
/////////////////////////////////////////////////////////////////////////
#define tstClose_Tophat2(dtype)						\
									\
  dtype rawsrc[]={0, 5, 0, 0, 0, 3, 8, 5, 0, 0,				\
		  0, 0, 7, 9, 7, 0, 8, 0, 0, 9,				\
		  0, 0, 5, 0, 0, 5, 8, 0, 5, 9,				\
		  0, 3, 0, 0, 0, 0, 0, 0, 0, 9,				\
		  3, 5, 3, 0, 5, 4, 5, 4, 0, 0,				\
		  2, 3, 3, 0, 4, 4, 4, 0, 3, 0,				\
		  2, 3, 0, 3, 4, 4, 4, 4, 0, 0,				\
		  0, 0, 5, 0, 5, 4, 0, 0, 0, 5};			\
									\
  dtype rawref[]={7, 2, 7, 9, 8, 5, 0, 3, 8, 9,				\
		  7, 7, 0, 0, 1, 8, 0, 8, 8, 0,				\
		  5, 5, 0, 5, 5, 0, 0, 8, 3, 0,				\
		  5, 2, 5, 5, 5, 5, 5, 5, 5, 0,				\
		  2, 0, 2, 5, 0, 1, 0, 1, 5, 5,				\
		  3, 2, 2, 5, 1, 1, 1, 5, 2, 5,				\
		  3, 2, 5, 2, 1, 1, 1, 1, 5, 5,				\
		  5, 5, 0, 5, 0, 1, 5, 5, 5, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(5, 5, 1, flgr_get_type_from_string(#dtype),FLGR_RECT, FLGR_8_CONNEX); \
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_close_tophat(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

#define tstClose_Tophat2_BIT						\
									\
  fgBIT rawsrc[]={0, 1, 0, 0, 0, 1, 1, 1, 0, 0,				\
		  0, 0, 1, 1, 1, 0, 1, 0, 0, 1,				\
		  0, 0, 1, 0, 0, 1, 1, 0, 1, 1,				\
		  0, 1, 0, 0, 0, 0, 0, 0, 0, 1,				\
		  1, 1, 1, 0, 1, 1, 1, 1, 0, 0,				\
		  1, 1, 1, 0, 1, 1, 1, 0, 1, 0,				\
		  1, 1, 0, 1, 1, 1, 1, 1, 0, 0,				\
		  0, 0, 1, 0, 1, 1, 0, 0, 0, 1};			\
									\
  fgBIT rawref[]={1, 0, 1, 1, 1, 0, 0, 0, 1, 1,				\
		  1, 1, 0, 0, 0, 1, 0, 1, 1, 0,				\
		  1, 1, 0, 1, 1, 0, 0, 1, 0, 0,				\
		  1, 0, 1, 1, 1, 1, 1, 1, 1, 0,				\
		  0, 0, 0, 1, 0, 0, 0, 0, 1, 1,				\
		  0, 0, 0, 1, 0, 0, 0, 1, 0, 1,				\
		  0, 0, 1, 0, 0, 0, 0, 0, 1, 1,				\
		  1, 1, 0, 1, 0, 0, 1, 1, 1, 0};			\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_fgBIT(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_fgBIT(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_fgBIT(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb =    flgr2d_create_neighborhood(3, 3, img->spp,img->type,		\
				      FLGR_RECT, FLGR_8_CONNEX);	\
  nhb->shape = FLGR_USER_SHAPE;						\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_close_tophat(img,imgsrc,nhb);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testclose_tophat2_fgBIT(void) {
  tstClose_Tophat2_BIT;
}
int testclose_tophat2_fgUINT8(void) {
  tstClose_Tophat2(fgUINT8);
}
int testclose_tophat2_fgUINT16(void) {
  tstClose_Tophat2(fgUINT16);
}
int testclose_tophat2_fgUINT32(void) {
  tstClose_Tophat2(fgUINT32);
}
int testclose_tophat2_fgINT8(void) {
  tstClose_Tophat2(fgINT8);
}
int testclose_tophat2_fgINT16(void) {
  tstClose_Tophat2(fgINT16);
}
int testclose_tophat2_fgINT32(void) {
  tstClose_Tophat2(fgINT32);
}
int testclose_tophat2_fgFLOAT32(void) {
  tstClose_Tophat2(fgFLOAT32);
}
int testclose_tophat2_fgFLOAT64(void) {
  tstClose_Tophat2(fgFLOAT64);
}



